package com.anjian.bamin.anjiandianzimap;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.CountDownTimer;
import android.os.IBinder;
import android.util.Log;

public class MyService extends Service {

    private long[] millisUntilFinished = new long[4];
    private TTSController ttsManager;

    public MyService() {
    }

    public class MyBind extends Binder{
        public void XunCha(){
            MyService.this.XunCha();
        }
        public long getMillisUntilFinished(int i){
            return MyService.this.getMillisUntilFinished(i);
        }
    }

    @Override
    public IBinder onBind(Intent intent) {
        return new MyBind();
    }

    public long getMillisUntilFinished(int i){
        return millisUntilFinished[i];
    }

    public void XunCha(){
        new CountDownTimer(60000/2, 1000) {
            public void onTick(long millisUntilFinished) {
                Log.e("onTick ", "onTick "+millisUntilFinished);
                MyService.this.millisUntilFinished[0]=millisUntilFinished;
            }
            public void onFinish() {
                Intent intent = new Intent();
                intent.putExtra("companyInfo", "泉州市鲤城区中科达机械设备有限公司");
                intent.setAction("server_broadcast");
                sendBroadcast(intent);
                ttsManager.startSpeaking();
                ttsManager.playText("您有新的巡查任务,去往"+"泉州市鲤城区中科达机械设备有限公司");
            }
        }.start();new CountDownTimer(60000*5, 1000) {
            public void onTick(long millisUntilFinished) {
                MyService.this.millisUntilFinished[1]=millisUntilFinished;
            }
            public void onFinish() {
                Intent intent = new Intent();
                intent.putExtra("companyInfo", "泉州市久久液压气动配件有限公司");
                intent.setAction("server_broadcast");
                sendBroadcast(intent);
                ttsManager.startSpeaking();
                ttsManager.playText("您有新的巡查任务,去往"+"泉州市久久液压气动配件有限公司");
            }
        }.start();new CountDownTimer(60000*100, 1000) {
            public void onTick(long millisUntilFinished) {
                MyService.this.millisUntilFinished[2]=millisUntilFinished;
            }
            public void onFinish() {
                Intent intent = new Intent();
                intent.putExtra("companyInfo", "泉州好利用机械设备有限公司");
                intent.setAction("server_broadcast");
                sendBroadcast(intent);
                ttsManager.startSpeaking();
                ttsManager.playText("您有新的巡查任务,去往"+"泉州好利用机械设备有限公司");
            }
        }.start();new CountDownTimer(60000*1000, 1000) {
            public void onTick(long millisUntilFinished) {
                MyService.this.millisUntilFinished[3]=millisUntilFinished;
            }
            public void onFinish() {
                Intent intent = new Intent();
                intent.putExtra("companyInfo", "泉州市金锦机电设备有限公司");
                intent.setAction("server_broadcast");
                sendBroadcast(intent);
                ttsManager.startSpeaking();
                ttsManager.playText("您有新的巡查任务,去往"+"泉州市金锦机电设备有限公司");
            }
        }.start();
    }

    @Override
    public void onCreate() {
        super.onCreate();
        //语音引擎初始化
        ttsManager = TTSController.getInstance(this);
        ttsManager.init();
        ttsManager.startSpeaking();
    }

    @Override
    public void onStart(Intent intent, int startId) {
        super.onStart(intent, startId);
//        CompanyList companyList = (CompanyList) intent.getSerializableExtra("companyList");
//        List<CompanyInfo> companyInfoList =  companyList.getCompanyInfoList();
//        mCompanyInfoList.addAll(companyInfoList);
    }
}
